<!DOCTYPE html>
<html>
  <head><meta name="generator" content="Hexo 3.9.0">
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=yes">
  
  
  <title>  创建Hexo脚本 |   XHX Blog </title>

 
  
    <link rel="icon" href="/images/avatar.jpg">
  


  <link rel="stylesheet" href="/nayo.min.css"> 
</head>  
  <body>   
    
      <header class="header-wrapper">

  <nav class="inner">
    <div class="title">
      <a href="/">
        <img class="logo" src="/images/avatar.jpg">
      </a>
    </div>

    <ul class="menu">
      
      
      <li class="item">
        <a class="link" id="menu-home" href="/">
          <i class="iconfont icon-home">
        </i></a>
      </li>
      
      
      
      <li class="item">
        <a class="link" id="menu-archives" href="/archives">
          <i class="iconfont icon-archives">
        </i></a>
      </li>
      
      
      
      <li class="item">
        <a class="link" id="menu-tags" href="/tags">
          <i class="iconfont icon-tags">
        </i></a>
      </li>
      
      
      
      <li class="item">
        <a class="link" id="menu-about" href="/about">
          <i class="iconfont icon-about">
        </i></a>
      </li>
      
      
      
      <li class="item">
        <a class="link" id="menu-search">
          <i class="iconfont icon-search">
        </i></a>
        

        
      
    </li></ul>
  </nav>
</header>

<header class="mobile-header-wrapper">
  <i id="mobile-toggle" class="iconfont icon-menu mobile-toggle"></i>
</header>   

      <div class="container">       
          
          
            <div class="container-inner">  
          

          <article class="post slideDownMin">
  
	
<div class="header">
		<p class="title">	
			创建hexo脚本
		</p>
		<div class="info">	
			<time>
				Jan 06, 2020
			</time>

			
			
				<i class="iconfont icon-words"></i>
				<span class="words">714
				</span>
			
		</div>
</div> 
	

    <script type="text/x-mathjax-config">
        var post = document.getElementsByClassName("post")[0];  
        MathJax.Hub.Config({
            showProcessingMessages: false,
            messageStyle: "none",    
            tex2jax: {
                inlineMath:  [ ["$", "$"] , ["\\(","\\)"]],
                displayMath: [ ["$$","$$"] , ["\\[","\\]"]],
                skipTags: ['script', 'noscript', 'style', 'textarea', 'pre','code','a'],
            },
            "HTML-CSS": {            
                showMathMenu: false
            }
        });
        MathJax.Hub.Queue(["Typeset",MathJax.Hub,post]);
    </script>
    <style>.MathJax{outline:0;}</style>

    <script type="text/javascript" src="//cdn.bootcss.com/mathjax/2.7.2/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
 

	  <div class="typo post-content ">

		

			
					<h1 id="起因"><a href="#起因" class="headerlink" title="起因"></a>起因</h1><p>本人创建<code>Hexo</code>脚本的痛点主要是2点：</p>
<ol>
<li>我用 vs code 的终端运行 hexo 命令和管理资源文件，用 Typora 撰写文章，因此每次不管是新建文章还是预览还是发布都需要来回切换，步骤较多挺麻烦的。</li>
<li>博客源码的版本管理。之前写过好几篇博文，可是在一次装机的过程中忘记迁移，结果丢失了原始markdown的文章和配置文件，导致无法继续写下去了，只得重头开始!<code>QAQ</code></li>
</ol>
<a id="more"></a>

<h1 id="脚本"><a href="#脚本" class="headerlink" title="脚本"></a>脚本</h1><p>基于以上2个原因，这里我创建了3个相关的脚本，还有一个麻烦一点正在实现中~</p>
<h2 id="1-新建文章"><a href="#1-新建文章" class="headerlink" title="1. 新建文章"></a>1. 新建文章</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> ~/repos/blog-src</span><br><span class="line">hexo new <span class="string">"&#123;query&#125;"</span></span><br><span class="line">open <span class="built_in">source</span>/_posts/&#123;query&#125;.md</span><br></pre></td></tr></table></figure>

<p>核心是<code>hexo new xx</code>命令，创建了新md文件，并使用open命令使用默认方式（我设置的是Typora）打开该文件开始写文章。</p>
<h2 id="2-本地运行博客"><a href="#2-本地运行博客" class="headerlink" title="2. 本地运行博客"></a>2. 本地运行博客</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> ~/repos/blog-src</span><br><span class="line">hexo clean</span><br><span class="line">hexo generate</span><br><span class="line">hexo server -p &#123;query&#125;</span><br><span class="line"></span><br><span class="line">open https://localhost:&#123;query&#125;</span><br></pre></td></tr></table></figure>

<p>有点像git的提交和本地运行，就是用hexo的server本地运行命令,运行启动后需要打开浏览器访问本地地址。由于hexo server把当前的终端挂起了，因此需要将访问页面的命令换个地方启动，这里直接把启动Chrome，访问localhost:{query}的操作放在输入之后，虽然会暂时显示无法访问，但是由于Chrome开启了自动重载特性，所以起起来后还是能显示博客，就暂先这么实现了。</p>
<h2 id="3-发布博客"><a href="#3-发布博客" class="headerlink" title="3. 发布博客"></a>3. 发布博客</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">// TODO</span><br></pre></td></tr></table></figure>

  	
					
	  </div>     
	  

	<div class="bottom">
  <div class="other">
    <div class="meta">
      

      
      <i class="iconfont icon-tag"></i>
      <a class="tag-link" href="/tags/hexo/">hexo</a> <a class="tag-link" href="/tags/productivity/">productivity</a>
      
    </div>

    <div class="operate">
      
      <span class="text">Share</span>
      <ul class="share">
	   			             
        <li class="iconfont 
		icon-share-qq 
		-mob-share-qq 
		item"></li>		
   	   			             
        <li class="iconfont 
		icon-share-weixin 
		-mob-share-weixin 
		item"></li>		
   	   			             
        <li class="iconfont 
		icon-share-weibo 
		-mob-share-weibo 
		item"></li>		
   	   
</ul>	

<script id="-mob-share" src="https://f1.webshare.mob.com/code/mob-share.js?appkey=21d601593a1de"></script>
      
    </div>
  </div>


  
  <nav class="nav">
    <div class="link">
      
      <a href="/2020/01/05/规则配置平台/" class="link-wrap">
        <strong class="caption">older</strong>
        
        <span class="title">
          规则配置平台
        </span>
      </a>
      
    </div>
    <div class="link">
      
      <a href="/2020/04/30/学以致用/" class="link-wrap">
        <strong class="caption">newer</strong>
        
        <span class="title">
          学以致用
        </span>
      </a>
      
    </div>
  </nav>
  
</div> 
	
<div class="comment">

    

    <div id="comment">
    </div>

    <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>

    <script src="//unpkg.com/valine@v1.1.8-beta/dist/Valine.min.js"></script>

    <script>
        new Valine({
            el: '#comment',
            notify: false,
            verify: false,
            app_id: 'cFM0eCo0CQ9xmBXmHi1eltol-gzGzoHsz',
            app_key: 'oh9tizsnvV2vNvWgqEvoNtQO',
            path: window.location.pathname,
            avatar: 'mm',
            guest_info: ['nick', 'mail']
        });
    </script>
    
</div>	
</article>

          </div> 
      </div>            
    
        <i id="toTop" class="iconfont icon-backtotop"></i>

  
    <div class="none" id="search">
    <div class="header">
        <input type="text" placeholder="Typing Something here." id="search-input" class="input">
        
        <i id="search-cancel" class="iconfont icon-cancel"></i>
    </div>

    <div id="search-result" class="result"></div>
</div>
     <div class="mobile-menu">      

      
      <img class="mobile-menu-icon" src="/images/avatar.jpg">  
      

         
            

            <a class="mobile-menu-link" href="/">Home
            </a>
            
         
            

            <a class="mobile-menu-link" href="/archives">Archives
            </a>
            
         
            

            <a class="mobile-menu-link" href="/tags">Tags
            </a>
            
         
            

            <a class="mobile-menu-link" href="/about">About
            </a>
            
         
                          

            <a class="mobile-menu-link mobile-menu-search" href="#">Search </a>                 
            
         
      
</div>
        
    



     
    


<footer class="footer">
	<div class="inner">
		<div class="copyright">
			&copy;
			
			2019 -
			
			2020
			Lemon

			<br>
			By <a href="https://hexo.io" target="_blank">Hexo</a> Theme <a href="https://github.com/Lemonreds/hexo-theme-Nayo" target="_blank">Nayo</a>
		</div>
	</div>
</footer>   

    <script src="/nayo.bundle.js"></script>           
  </body>        
</html>